 <template>
  <div class="wrap">
    <div class="title">
      <img src="../../images/main/mine.png"
        alt> 用户管理
    </div>
    <div class="screen">
      <img src="../../images/main/screen.png"
        alt> 筛选查询
    </div>
    <div class="sel">
      <div class="txt">关键词：</div>
      <input v-model="form.keyWord"
        type="text"
        placeholder="用户名/手机号">
      <div class="btn"
        @click="querys()" style="cursor: pointer;">搜索</div>
    </div>
    <div class="clear"></div>
    <div class="table" v-loading="loading">
      <div class="thead">用户列表</div>
      <div class="sthead">
        <div class="userimg">头像</div>
        <div class="username">用户名称</div>
        <div class="phone">手机号</div>
        <div class="zctime">注册时间</div>
        <div class="ctrl lastlist">操作</div>
      </div>
      <div class="tlists">
        <div v-if="userList.length == 0" style="height:60px;line-height:60px;border:1px solid #ccc;text-align:center;">
          暂无数据
        </div>
        <div class="tlist"
        v-else
          v-for="(items, index) in userList"
          :key="index">
          <div class="userimg">
            <img :src="items.userImg"
              alt>
          </div>
          <div class="username">{{items.nickName}}</div>
          <div class="phone">{{items.userPhone}}</div>
          <div class="zctime">{{setDate(items.registerTime)}}</div>
          <div class="ctrl lastlist" @click="setUser(items.states,items.id)">
              {{items.states == 1 ? '解除禁止' : '禁止'}}
          </div>
        </div>
      </div>
    </div>
    <div style="text-align: center;padding: 50px 0;">
      <el-pagination background
        layout="prev, pager, next"
        @current-change="changePage"
        :page-count="pageTotal">
      </el-pagination>
    </div>
  </div>
</template>
<script>
import axios from "axios";
import qs from "qs";
export default {
  data() {
    return {
      loading: false,
      userList: [],
      pageTotal: 1,
      // 页面初始化
      form: {
        keyWord: "",
        page: "1",
        limit: ""
      }
    };
  },
  mounted: function() {
    this.getUserList();
  },
  methods: {
    // 分页
    changePage(argv) {
      this.form.page = argv;
      this.getUserList();
    },
    /**
     * 冻结
     */
     setUser: function (state,id) {
       let that = this;
      that.$confirm(state==0 ?'是否禁止该用户？' : '是否解除禁止该用户？').then( ()=>{
        if(state == 0) {
          state = 1
        } else {
          state = 0
        }
        axios({
        method: "post",
        url: `${that.$store.state.url}/tUser/updateStates`,
        data: qs.stringify({
          id:id,
          states:state
        })
      }).then(res => {
        that.userList = res.data.data;
        if (res.data.code == 0) {
          that.getUserList();
        } else {
          that.$alert(res.data.msg)
        }
      }).catch(err => {
        
      });
      })
     },
    // 点击搜索
    querys: function() {
      this.getUserList();
    },
    /**
     * 根据时间毫秒数 返回年月日
     */
    setDate: function(str) {
      let times = new Date(str);
      return `${times.getFullYear()}-${
        times.getMonth()+ 1 < 10 ? "0" + (times.getMonth() + 1): times.getMonth() + 1
      }-${times.getDate() < 10 ? "0" + times.getDate() : times.getDate()}`;
    },
    // 查询用户
    getUserList: function() {
      this.loading = true;
      let that = this;
      axios({
        method: "post",
        url: `${that.$store.state.url}/tUser/selectByKyWord`,
        data: qs.stringify(that.form)
      }).then(res => {
        this.userList = res.data.data;
        if (res.data.code == 0) {
          this.pageTotal = Math.ceil(res.data.count / 10);
        }
        this.loading = false;
      }).catch(err => {
        this.loading = false;
      });
    },
    editParMan: function() {
      this.$router.push({
        path: "main/editParMan"
      });
    },
    accParMan: function() {
      this.$router.push({
        path: "main/accParMan"
      });
    }
  }
};
</script>
<style scoped>
.wrap {
  /* padding: 68px 136px; */
  width: 90%;
  margin: 40px auto;
}
.title {
  height: 33px;
  line-height: 33px;
  font-size: 24px;
  font-family: PingFangSC-Medium;
  font-weight: bold;
}
.title img {
  width: 28px;
  height: 26px;
  float: left;
  padding-top: 5px;
  margin-right: 10px;
}
.screen {
  /* width: 1490px; */
  height: 60px;
  background: #f6f6f6;
  margin-left: 38px;
  margin-top: 24px;
  line-height: 60px;
  font-family: PingFangSC-Medium;
  font-size: 18px;
  color: #888888;
}
.screen img {
  float: left;
  width: 27px;
  height: 27px;
  margin-left: 10px;
  margin-top: 16px;
  margin-right: 18px;
}
.sel {
  margin-top: 27px;
  padding-left: 38px;
  height: 40px;
  line-height: 40px;
}
.sel .txt {
  float: left;
  font-family: PingFangSC-Medium;
  font-size: 18px;
  color: #000000;
  font-weight: bold;
  width: 73px;
}
.sel input {
  float: left;
  background: #ffffff;
  box-shadow: inset 0 1px 3px 0 rgba(0, 0, 0, 0.5);
  width: 317px;
  height: 40px;
  font-family: PingFangSC-Medium;
  font-size: 18px;
  color: #888888;
  margin-left: 17px;
  text-align: center;
  box-sizing: border-box;
}
.btn {
  float: left;
  color: #fff;
  background: #085dab;
  border: 1px solid #085dab;
  width: 140px;
  height: 38px;
  text-align: center;
  margin-left: 37px;
}
.table {
  /* width: 1490px; */
  margin-top: 43px;
  margin-left: 38px;
}
.table .sthead {
  border-bottom: 1px solid #dddddd;
  height: 67px;
  font-family: PingFangSC-Medium;
  font-size: 20px;
  color: #000000;
  line-height: 67px;
  font-weight: bold;
  background: #e0eefe;
}
.userimg {
  /* width: 310px; */
  width: 20%;
}
.userimg img {
  width: 130px;
  height: 130px;
  margin:  0 auto;
  margin-top: 6px;
}
.sthead > div {
  float: left;
  border-left: 1px solid #ddd;
  text-align: center;
  box-sizing: border-box;
}
.username {
  /* width: 267px; */
  width: 20%;
}
.phone {
  /* width: 352px; */
  width: 20%;
}
.zctime {
  /* width: 319px; */
  width: 20%;
}
.table .thead {
  text-align: left;
  font-family: PingFangSC-Medium;
  font-size: 24px;
  color: #000000;
  height: 69px;
  line-height: 69px;
  padding-left: 15px;
  background: #e0eefe;
  border: 1px solid #dddddd;
  box-sizing: border-box;
  font-weight: bold;
}
.addpar {
  background: #f6f6f6;
  border: 1px solid #085dab;
  border-radius: 2px;
  width: 107px;
  height: 33px;
  float: right;
  font-family: PingFangSC-Regular;
  font-size: 14px;
  line-height: 33px;
  margin-top: 17px;
  margin-right: 20px;
  color: #085dab;
  cursor: pointer;
}
.add {
  width: 18px;
  height: 18px;
  float: left;
  margin: 8px;
}
.tbody .zctime {
  padding-left: 50px;
  box-sizing: border-box;
}
/* .table div {
        font-family: PingFangSC-Medium;
        font-size: 18px;
        color: #4a4a4a;
        border: 1px solid #dddddd;
        height: 142px;
        text-align: center;
    } */
.ctrl {
  /* width: 241px; */
  width: 20%;
}
.tlist {
  height: 142px;
  line-height: 142px;
  border: 1px solid #ddd;
  box-sizing: border-box;
  overflow: hidden;
}
.lastlist {
  border-right: 1px solid #ddd;
}
.tlist > div {
  height: 142px;
  float: left;
  text-align: center;
  border-right: 1px solid #ddd;
  box-sizing: border-box;
}

.tlist .ctrl {
  color: #085dab;
  cursor: pointer;
  font-weight: bold;
}
.tlist > div::after {
  content: "";
  display: block;
  padding-bottom: 100%;
}
.tlist:last-of-type {
  border-bottom: 1px solid #ddd;
}
.ctrl ul {
  width: 179px;
  padding: 18px 19px 20px 31px;
  height: 104px;
}
.ctrl ul li {
  float: left;
  width: 72px;
  height: 25px;
  line-height: 25px;
  text-align: center;
  font-family: PingFangSC-Medium;
  font-size: 18px;
  color: #085dab;
  margin-top: 15px;
  font-weight: bold;
  cursor: pointer;
}
.ctrl ul li:nth-of-type(2n) {
  margin-left: 35px;
}
.ctrl .firli {
  margin-top: 0px;
}
.clear {
  clear: both;
}
</style>
